#ifndef _Game_h_
#define _Game_h_

/** @file	Game.h 
    @author	Julien CLEMENT
    @brief	Data structures involved in BnB.
		The top-level data structure is "Game",
		all the other ones are aggregated to it
		directly or indirectly.
    @note	Global variables could have been used, but
		using data structures allow data organization
		following the game logic.
*/

		

#include "SDL.h"
/*#include "SFont.h"*/
#include "SDL_Layer.h"
/*#include "Level.h"*/
#include "Gfx.h"

/* Access particular information for a player */
#define NPLAYERS	( 2 )
#define PLAYER_1	( 0 )
#define PLAYER_2	( 1 )

/* Select the appropriate font size */
#define NFONTS		( 3 )
#define FONT_SMALL	( 0 )
#define FONT_MEDIUM	( 1 )
#define FONT_BIG	( 2 )

/* Available game modes */
enum GameMode
 {
	MODE_A		= 0,
	MODE_B		= 1
 };


/* Game resources */
typedef struct
{
	/* 4 different balls:
	   one per mode, one per player (different colors) */
	SDL_Surface * balls[NMODES][NPLAYERS];
	
	/* Brick tilesets.
	   The encoding of bricks is explained
	   in BnB.txt */
	SDL_Surface * bricks[NMODES];

	/* Fonts used for printing out textual information:
	   FONT_SMALL, FONT_MEDIUM, FONT_BIG */
	SFont_Font  * fonts[NFONTS];

	/* LCD display effect surface */
	SDL_Surface * lcd;
}Resource;


/* Graphical area information & data */
typedef struct
{
	/* Main zones of the game, used both for clipping
	   and for collision detection. */
	SDL_Rect area_Bricks;		/*< Zone containing the bricks (different in mode A/B) */
	SDL_Rect area_Control[2];	/*< Zones containing each player's edges & pin */
	SDL_Rect area_LCD[2];		/*< Zones containing each player's LCD */

	SDLayer_Display	* display	/*< Layered display */
	SDL_Surface * screen_buffer;	/*< Surface with the same size & format
					    as the screen */
}Gfx;

typedef struct
{
	double	ballx, bally, ballx_old, bally_old;
	double	balldx, balldy;
	double	speed;
	int	ballx_i, bally_i;	
	SDL_Rect pinrect;
}Physics;


typedef struct
{
	/* Player specific gfx */
	/*SDL_Surface * pin;
	SDL_Surface * ball, * ball_mask;
	*/
	/* Player status */
	/*int attempts;
	int lost;
	int won;
	int lifes;
	int nlosts;
	int flicks;
	long score;
	*/
	/* Player physics */
	Physics phys;	
}Player;

typedef struct
{
	enum GameMode mode;		/*< Game mode */

#define GAME_RUNNING		0x1
#define GAME_NEED_REFRESH	0x2
#define GAME_SOUND_ON		0x4
	int flags;

	/* Maximum: 2 players */
	Player players[2];

	/* Resources */
	Resource resource;

	/* GFX */
	Gfx gfx;

	/* Current level */
	/*Level lvl;
	int level;
	*/
}Game;

extern Game game;

void score_incr (long value);
void score_bonus_endlevel (void);
void score_raise (long value);
void score_check_extra_ball(void);
void score_sprintf (char * str, long score);

#endif

